//
//  ViewController.swift
//  简单的位移动画
//
//  Created by app on 2017/4/12.
//  Copyright © 2017年 app. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    var loginButton:UIButton?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        loginButton = UIButton(frame: CGRect(x: -394, y: 230, width:view.frame.width - 40 , height: 50))
        loginButton?.backgroundColor = UIColor.red
        loginButton?.setTitle("我是按钮", for: .normal)
        
        view.addSubview(loginButton!)
        
        
    }
    
    // 简单的改变frame动画
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        //        UIView.beginAnimations(nil, context: nil)
        //        UIView.setAnimationDuration(1)
        //        self.loginButton?.frame = CGRect(x: 20, y: (self.loginButton?.frame.origin.y)!, width: (self.loginButton?.frame.width)!, height: 50)
        //        UIView.commitAnimations()
        
        UIView.animate(withDuration: 1) {
            self.loginButton?.frame = CGRect(x: 20, y: (self.loginButton?.frame.origin.y)!, width: (self.loginButton?.frame.width)!, height: 50)
        }
        
        UIView.beginAnimations(nil, context: nil)
        UIView.setAnimationDuration(3)
        loginButton?.bounds = CGRect(x: 0, y: 0, width: (loginButton?.frame.width)! * 0.7, height: (loginButton?.frame.size.height)! * 1.2)
        UIView.commitAnimations()
    }
    
}

